<?php
namespace Todo\Service;
use Todo\Model\Doc\ViewModel;
use Todo\Model\FilesModel;
use Todo\Utils\ConvertX;
use Todo\Utils\Files;
use Todo\Utils\String;

/**
 * Created by PhpStorm.
 * User: yepanpan
 * Date: 2016/8/8
 * Time: 17:08
 */
class SiteService extends BaseService
{
    private static $__INSTANCE = null;

    public static function getInstance(){
        if(!self::$__INSTANCE) self::$__INSTANCE = new SiteService();

        return self::$__INSTANCE;
    }

    /**
     * 查询当前全部站点，实现内存缓存
     * @return mixed
     */
    public function getAll(){
        $list = $this->cache('site_list');
        if($list) return $list;

        $list = D('Todo/Cms/Site')->where(array('status'=>1))->select();;
        $this->cache('site_list', $list);
        return $list;
    }
    
    /**
     * 查询当前站点全部栏目，实现内存缓存
     * @param int $siteId 站点ID
     * @return mixed
     */
    public function getSiteCategory($siteId){
        $key = 'cate_list_'.$siteId;
        $list = $this->cache($key);
        if($list) return $list;

        $list =  D('Todo/Cms/Category')->where(array('status'=>1, 'site_id'=>$siteId))->select();
        $this->cache($key, $list);
        return $list;
    }

    /**
     * 查询栏目的模型信息
     * @param int $cateId 栏目ID
     * @return mixed
     */
    public function getCategoryModel($cateId){
        $cateInfo  = D('Todo/Cms/Category')->keyFind($cateId);
        if(!$cateInfo) return false;

        $modelInfo = D('Todo/Cms/Models')->keyFind($cateInfo['model_id']);
        if($modelInfo['pid']){
            $modelInfo['base'] = D('Todo/Cms/Models')->keyFind($modelInfo['pid']);
        }
        return $modelInfo;
    }

}